package com.woniuxy.riskmanage.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.woniuxy.commons.entity.PageBean;
import com.woniuxy.commons.entity.RiskRules;
import com.woniuxy.commons.utils.ResponseResult;
import com.woniuxy.riskmanage.service.RuleService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author author
 * @create 2021-11-22 11:22
 */
@RestController
@RequestMapping("/rules")
public class RuleController {

    @Resource
    private RuleService ruleService;

    /**
     * 分页查询
     */
    @SentinelResource(value = "selectPage", fallback = "fallbackSelectPage")
    @GetMapping("/selectPage")
    public ResponseResult<PageBean<RiskRules>> selectPage(RiskRules riskRules, Integer pageSize, Integer pageIndex) {
        System.out.println("查询条件:" + riskRules);
        System.out.println("pageSize:" + pageSize);
        System.out.println("pageIndex:" + pageIndex);
        PageBean<RiskRules> pageBean = new PageBean<>();
        int countRulesByPage = ruleService.selectRulesCountBylimit(riskRules);
        List<RiskRules> rules = ruleService.selectAllRules(riskRules, pageIndex, pageSize);
        pageBean.setBeanList(rules);
        pageBean.setPageIndex(pageIndex);
        pageBean.setPageSize(pageSize);
        pageBean.setTotalRecord(countRulesByPage);
        return new ResponseResult<PageBean<RiskRules>>(200, null, "获取成功", pageBean);
    }

    /**
     * 分页查询降级方法
     *
     * @return
     */
    public ResponseResult<PageBean<RiskRules>> fallbackSelectPage() {
        return new ResponseResult<>(500, null, "系统维护中", null);
    }

//    /**
//     * 修改订单状态
//     *
//     * @param orders
//     * @return
//     */
//    @LogRequirePerms(description = "修改订单状态")
//    @RequirePerms("user:update")//修改权限
//    @SentinelResource(value = "orderStates", fallback = "fallPutOrderState")//开启哨兵
//    @PutMapping("/orderState")
//    public ResponseResult logPutOrderState(@RequestBody Orders orders) {
//        System.out.println("orders" + orders);
//        ordersService.updateOrdersById(orders);
//        return new ResponseResult(200, null, "修改成功", null);
//    }
//
//    /**
//     * 修改订单状态降级方法
//     *
//     * @return
//     */
//    public ResponseResult fallPutOrderState() {
//        return new ResponseResult(500, null, "系统维护中", null);
//    }
    }
